<cfcomponent displayname="PersonGateway" output="true">

	<cffunction name="getUsers" access="remote" returntype="query" output="false">
		<cfset var queryUsers = "" />

		<cfquery name="queryUsers" datasource="tidtool">
			SELECT * FROM Person
			ORDER BY Username ASC
		</cfquery>
		<cfreturn queryUsers />
	</cffunction>

	<cffunction name="getUserByUsername" access="remote" returntype="query" output="false">
		<cfset var queryUser = "" />
		<cfquery name="queryUser" datasource="tidtool">
			SELECT * FROM Person
			WHERE
				Username = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.currentUsername#" />
		</cfquery>
		<cfreturn queryUser />
	</cffunction>

	<cffunction name="updateUserByUsername" access="remote" returntype="any" output="false">
		<cfset var query = "" />
		<cfset var message = "" />
		<cfquery name="query" datasource="tidtool">
			UPDATE Person
			SET
				Email = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.email#" />,
				<cfif structKeyExists(form, "password") and len(form.password) gt 0>
					Password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#hash(form.password)#" />,
				</cfif>
				CurrentStep = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.step#" />
			WHERE
				Username = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.username#" />
		</cfquery>
		<cfset message = "erfolgreich gespeichert" />
		<cfreturn message />
	</cffunction>

	<cffunction name="getPendingUsers" access="remote" returntype="query" output="false">
		<cfset var queryPendingUsers = "" />
		<cfquery name="queryPendingUsers" datasource="tidtool">
			SELECT * FROM Person
			WHERE
				Roles = <cfqueryparam cfsqltype="cf_sql_varchar" value="pending" />
		</cfquery>
		<cfreturn queryPendingUsers />
	</cffunction>

</cfcomponent>